import parcomb.ParcombPackage;
import javaCC.ProgGrammar;
import miny_pascal.ParserUser;
import antlr.Test;
import testaux.*;

public class Testing {
    public static String fileName = "C:\\LIB\\prog5.txt";
    public static void main(String[] args) throws Exception {
        long startTime, endTime;
        long time1, time2, time3, time4;
        int result1, result2, result3, result4;
        Program res1, res2, res3, res4;

        // 1 - Parser Comnbinators
        startTime = System.nanoTime();
        res1 = ParcombPackage.parse(fileName);
        endTime = System.nanoTime();
        time1 = endTime - startTime;

        //output_old("Kotlin parser combinators", evaluate(res1), time1);
        output("Kotlin parser combinators", res1, time1);

        // 2 - JLex + CUP
        startTime = System.nanoTime();
        res2 = ParserUser.run(fileName);
        endTime = System.nanoTime();
        time2 = endTime - startTime;

        //output_old("JLex + CUP", evaluate(res2), time2);
        output("JLex + CUP", res2, time2);
           /*
        // 3 - ANTLR
        startTime = System.nanoTime();
        res3 = Test.run(fileName);
        endTime = System.nanoTime();
        time3 = endTime - startTime;

        //output_old("ANTLR", evaluate(res3), time3);
        output("ANTLR", res3, time3);
                      */
        // 4 - JavaCC
        startTime = System.nanoTime();
        res4 = ProgGrammar.run(fileName);
        endTime = System.nanoTime();
        time4 = endTime - startTime;

        //output_old("JavaCC", evaluate(res4), time4);
        output("JavaCC", res4, time4);

    }


    public static void output(String name, Object result, long time) {
        System.out.println(name);
        System.out.format(/*"Result hash: " + result.toString().length() + */"\nTime of Execution: %15d = %12d = %9d\n\n", time, time / 1000, time / 1000000);
    }

    public static void output_old(String name, int result, long time) {
        System.out.println(name);
        System.out.format("Result: %10d ; Time of Execution: %15d\n\n", result, time);
    }
                        /*
    public static int evaluate(Expr t) {
        switch (t.getType()) {
            case Expr.ADD:
                return evaluate(t.get(0)) + evaluate(t.get(1));
            case Expr.MIN:
                return evaluate(t.get(0)) - evaluate(t.get(1));
            case Expr.MUL:
                return evaluate(t.get(0)) * evaluate(t.get(1));
            case Expr.INTCONST:
                return ((Integer)t.getData()).intValue();
            default:
                return 0;
        }
    }                     */
}
